/**
 * @file
 * Monitor_ChipTest.c 
 * @author Brian Kang
 * @version 1.0
 * @section LICENSE
 *	Copyright (C) 2011~2012 Intersil Corporation
 * @section DESCRIPTION
 *	Interface between TW_Terminal2 and Firmware.
*/
//*****************************************************************************
//
//								Monitor_ChipTest.c
//
//*****************************************************************************
//
//
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "TW8836.h"

#include "Global.h"
#include "CPU.h"
#include "printf.h"
#include "util.h"
#include "monitor_MENU.h"
#include "reg_debug.h"

#include "main.h"
#include "i2c.h"
#include "spi.h"
//#include "menu8835.h"
#include "Remo.h"

#include "SOsd.h"
#include "FOsd.h"
#include "SOsdMenu.h"

#include "Demo.h"
#include "SpiFlashMap.h"

#ifdef SUPPORT_FOSD_MENU
#include "FOsdMenu.h"
#endif

//temp..please move to .h file and remove it
extern 		void MenuCheckTouchInput(BYTE TscStatus,int x,int y);
extern		void proc_home_menu_start(void);

extern void DumpFontOsdPalette(void);
extern void Test16x32FontSet(void);
extern void TestUpper256Char(void);
extern void TestMultiBPP4(void);
extern void TestNum1BPP3BPP(void);

extern void TaskSetGridCmd(BYTE cmd);
extern BYTE TaskGetGrid(void);


//extern XDATA BYTE Task_Grid_on;
extern void MenuKeyInput(BYTE key);

//extern TestMainMenuImage(BYTE type);

void MonitorChipTest_Info(void)
{
	Puts("\n  === Help for ChipTest command ===");
	Puts("\nCTest reg rw		;register read/write test");
	Puts("\nCTest reg default	;register default value");
	Puts("\nCTest gpio			;gpio test");
	Puts("\nCTest sosdlut		;SpiOSD LUT readback test");
	Puts("\nCTest dma [n_wait]	;spiflash dma wait test");
	Puts("\nCTest resume		;power suspend resume");
}

//REG0D4[0] it makes a reset. Remove:W
code BYTE DefPage0Regs[256] = {
    /*         0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
	/*000:*/0x78,0xBF,0x00,0xFF,0x00,0xBF,0x00,0x00,0x30,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0x00,
	/*010:*/0xBF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0x00,0xBF,0x00,0x80,0x00,0x80,0x00,0x55,0x80,0x00,0x80,0x00,
	/*0E0:*/0xF2,0x77,0x04,0x40,0x84,0x00,0x20,0xBF,0xF2,0x0A,0x04,0x40,0x20,0x80,0x20,0xBF,
	/*0F0:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0x00,0x16,0x01,0x20,0x00,0x40,0x30,0x11,0xBF,0x00 };
//REG006 makes hang. 120628 it was 0xFF
//REG0D4[0] makes reset.
code BYTE RegMask_W_Page0[256] = {
	/*000:*/0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*010:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*030:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0xFE,0x37,0x7F,0x0F,0xFF,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*090:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0xFF,0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0xFE,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*0E0:*/0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00 };
code BYTE RegMask_R_Page0[256] = {
	/*000:*/0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*010:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*030:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0xFE,0x37,0x7F,0x0F,0xFF,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*090:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*0A0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0xFF,0xFF,0xFF,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00 };


code BYTE DefPage1Regs[256] = {
    /*         0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
	/*100:*/0xBF,0x00,0x40,0x00,0x00,0x00,0x00,0x12,0x12,0x20,0x10,0xD0,0xCC,0x15,0xBF,0xBF,
	/*110:*/0x00,0x64,0x11,0x80,0x80,0x00,0x00,0x30,0x44,0x00,0x00,0x00,0x07,0x7F,0x08,0x00,
	/*120:*/0x50,0x42,0xF0,0xD8,0xBC,0xB8,0x44,0x2A,0x00,0x00,0x78,0x44,0x30,0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xBF,0xBF,0xBF,
	/*1F0:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0x00 };
code BYTE RegMask_W_Page1[256] = {
	/*000:*/0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0x0F,0xFF,
	/*020:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*030:*/0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0xFF,0x00,0xFF,0x0F,0xFF,0x1F,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*0D0:*/0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
code BYTE RegMask_R_Page1[256] = {
	/*000:*/0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*020:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*030:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0xFF,0xFF,0xFF,0x0F,0xFF,0x1F,0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*0D0:*/0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };


code BYTE DefPage2Regs[256] = {
    /*         0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
	/*200:*/0xBF,0x00,0x20,0x00,0x20,0x00,0x20,0x80,0x10,0x00,0x04,0x30,0xD0,0x00,0x20,0x00,
	/*210:*/0x10,0x00,0x03,0x10,0x20,0x20,0x00,0x03,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0xBF,
	/*220:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*230:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*240:*/0x10,0x00,0x01,0x00,0x00,0x01,0x00,0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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,
	/*020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*030:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0xFF,0xFF,0x03,0xFF,0x77,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0xFF,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00 };
code BYTE RegMask_R_Page2[256] = {
	/*000:*/0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,
	/*020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*030:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0xFF,0xFF,0x03,0xFF,0x77,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00 };


code BYTE DefPage3Regs[256] = {
    /*         0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
	/*300:*/0x00,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x00,0x00,0x00,0xBF,
	/*310:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*320:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*330:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*340:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*350:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*360:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*370:*/0x00,0x00,0x00,0x00,0x00,0x00,0x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:*/0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*040:*/0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*050:*/0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*060:*/0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*070:*/0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*080:*/0xFF,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*090:*/0xFF,0xFF,0x0F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };


code BYTE DefPage4Regs[256] = {
    /*         0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
	/*400:*/0x00,0xBF,0xBF,0xBF,0x00,0x00,0x00,0x00,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0x00,0x45,
	/*410:*/0x00,0x00,0x00,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*420:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*430:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*440:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*450:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*460:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*470:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*480:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*490:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*4A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*4B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,
	/*4C0:*/0x00,0x00,0x00,0x40,0x80,0x80,0x04,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,
	/*4D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x08,0x00,0x00,0x00,0x00,0x01,0x00,
	/*4E0:*/0x00,0x06,0x00,0x90,0x00,0x90,0x00,0x90,0x00,0x0C,0x00,0x0C,0xBF,0xBF,0xBF,0xBF,
	/*4F0:*/0x00,0x00,0x00,0x40,0x00,0x00,0x04,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
//REG4C2 makes hang. it was 0x01
code BYTE RegMask_W_Page4[256] = {
	/*000:*/0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
	/*010:*/0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*020:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*030:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	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xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*0D0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0xFF,0xFF,0x1F,0x10,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
	/*0F0:*/0x07,0x01,0x10,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00 };


code BYTE DefPage5Regs[256] = {
    /*         0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F */
	/*500:*/0x00,0x20,0x01,0xE0,0x00,0x20,0x00,0xDA,0x00,0x00,0x00,0x8C,0xBF,0xBF,0xBF,0xBF,
	/*510:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*520:*/0x80,0x80,0x00,0x00,0x10,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*530:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xBF,
	/*540:*/0xFF,0x00,0xFF,0x08,0x3D,0x5F,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*550:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*560:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*570:*/0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,0xBF,
	/*580:*/0xBF,0xBF,0xB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00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
code BYTE RegMask_R_Page5[256] = {
	/*000:*/0x07,0xFF,0x0F,0xFF,0x07,0xFF,0x07,0xFF,0x0F,0x7F,0x8F,0xFF,0x00,0x00,0x00,0x00,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*020:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*030:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };



void ChipTest_Register_RW(BYTE page)
{
	BYTE *pDefData, *pWMask, *pRMask, Mask;
	BYTE i,j,Index;
	WORD PageIndex;
	BYTE prev_data;
	volatile BYTE value;

	//link data
	switch(page) {
	case 0: pDefData = DefPage0Regs; pWMask = RegMask_W_Page0; pRMask = RegMask_R_Page0;	break;
	case 1: pDefData = DefPage1Regs; pWMask = RegMask_W_Page1; pRMask = RegMask_R_Page1;	break;
	case 2: pDefData = DefPage2Regs; pWMask = RegMask_W_Page2; pRMask = RegMask_R_Page2;	break;
	case 3: pDefData = DefPage3Regs; pWMask = RegMask_W_Page3; pRMask = RegMask_R_Page3;	break;
	case 4: pDefData = DefPage4Regs; pWMask = RegMask_W_Page4; pRMask = RegMask_R_Page4;	break;
	case 5: pDefData = DefPage5Regs; pWMask = RegMask_W_Page5; pRMask = RegMask_R_Page5;	break;
	}
	Printf("\nPage:%bd================", page);
	for(i=0; i < 16; i++ ) {
		for(j=0; j < 16; j++) {
			//default value check
			Index = i*16+j;
			PageIndex = ((WORD)page << 8) + Index;
			Mask = pWMask[Index] | pRMask[Index];
			if(pWMask[Index]) {
				Printf("\nREG%01bx%02bx WMask:%02bx RMask:%02bx Def:%02bx",page, Index, pWMask[Index], pRMask[Index], pDefData[Index]);

				value = ReadTW88(PageIndex);
	
				if((value & Mask) != (pDefData[Index] & Mask)) {
					Printf(" Read:%02bx", value);
				}
			}
			else if(pRMask[Index]) {
				//read only.
				Printf("\nREG%01bx%02bx WMask:%02bx RMask:%02bx Def:__",page, Index, pWMask[Index], pRMask[Index]);

				value = ReadTW88(PageIndex);
				Printf(" Read:%02bx", value);
			}
			else if(pDefData[Index]==0xBF) {
				value = ReadTW88(PageIndex);
				if(value != 0xBF) {
					Printf("\nREG%01bx%02bx BF. Read:%02bx", page, Index, value);

					WriteTW88(PageIndex, 0xFF);
					value = ReadTW88(PageIndex);
					if(value != 00) {
						Printf("\nREG%01bx%02bx BF. but writable.", page, Index);
					}
				}
				else {
					//assume NO register.
				}
			}

			//skip
			if(PageIndex == REG4E1)	{ //it is a clock
				Puts("->skip");
				continue;
			}

			//write test
			if(pWMask[Index]) {
				prev_data = ReadTW88(PageIndex);

				WriteTW88(PageIndex, 0x00);
				value = ReadTW88(PageIndex);
				if(value != 0x00) {
					//Printf(" REG%01bx%02bx W:00 R:%02bx", page,Index,value);
					Printf(" W:00_R:%02bx", value);
				}
				WriteTW88(PageIndex, 0xFF & pWMask[Index]);
				value = ReadTW88(PageIndex);
				if((value & pWMask[Index]) != (0xFF & pWMask[Index])) {
					//Printf(" REG%01bx%02bx W:%02bx R:%02bx", page,Index, pWMask[Index], value);
					Printf(" W:%02bx_R:%02bx", pWMask[Index], value);
				}
				WriteTW88(PageIndex,prev_data);
			}
		}
	} 
}


void ChipTest_Register_ReadWrite(void)
{
	ChipTest_Register_RW(0);
	ChipTest_Register_RW(1);
	ChipTest_Register_RW(2);
	ChipTest_Register_RW(3);
	ChipTest_Register_RW(4);
	ChipTest_Register_RW(5);
	
}


//-----------------------------------
/*
If GPIO is connected with a SPIFlash, FW can not check this pin.
GPIO_05 - SPIDI2
GPIO_06 - SPIDI3

If you see the fail result, check the value manually. 
the result can be different depend on the board.
*/
code BYTE GPIO_mask[] = { 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

void ChipTest_GPIO(void)
{
	DECLARE_LOCAL_page
	BYTE prev_en,prev_oe,prev_od;
	BYTE value;
	BYTE i;
	BYTE result;

	ReadTW88Page(page);
	WriteTW88Page(0);
	//GPIO0~6
	for(i=0; i < 7; i++) {
		result = ERR_SUCCESS;
		Printf("\nGPIO_%01bxx ",i);
		//read previous value
		prev_en = ReadTW88(REG080+i);
		prev_oe = ReadTW88(REG088+i);
		prev_od = ReadTW88(REG090+i);
		value = ReadTW88(REG098+i);
		Printf("PREV EN:%02X OE:%02X OD:%02X ID:%02X ", prev_en,prev_oe,prev_od,value);

		WriteTW88(REG080+i, 0xFF & GPIO_mask[i]);  		//enable GPIO
		WriteTW88(REG088+i, 0xFF & GPIO_mask[i]);  		//output enable
		WriteTW88(REG090+i, 0xFF & GPIO_mask[i]);  		//output data
		value= ReadTW88(REG098+i) & GPIO_mask[i];		//read input
		Printf(" W:%02bx R:%02bx ",0xFF & GPIO_mask[i], value);
		if((0xFF & GPIO_mask[i]) != (value & GPIO_mask[i])) 
			result = ERR_FAIL;


		WriteTW88(REG090+i, 0x00);  					//output data
		value=ReadTW88(REG098+i) & GPIO_mask[i];		//read input
		Printf(" W:00 R:%02bx ",value);
		if((value & GPIO_mask[i])) 
			result = ERR_FAIL;

		if(result==ERR_SUCCESS)
			Puts(" Pass");

		//restore orginal value
		WriteTW88(REG080+i, prev_en);
		WriteTW88(REG088+i, prev_oe);
		WriteTW88(REG090+i, prev_od);
	}
	WriteTW88Page(page);
}

/*
DMA for SPI LUT needs a PCLK divider 2 on the TW8835.
LutOffset
size
address: LUT data location at SPIFlash.
example: ctest sosdlut 1 0 100 410010	 <--logo
         ctest sosdlut 1 0 100 41e081    <- setup menu, main background
*/
void ChipTest_SOsdLut(BYTE winno, WORD LutOffset, WORD size,DWORD address)
{
	WORD ii;
	BYTE j;
	BYTE bgra[4], value;
	volatile BYTE B0;
	BYTE rcount;
	WORD error=0;

	//write LUT	by DMA
	SpiOsdLoadLUT(winno, /*type=*/1, LutOffset, size*4, address, 0xFF);

	//read back test
	for(ii=LutOffset; ii < (LutOffset+size); ii++) {

		//read BGRA data at REG4D0~REG4D3
		//SpiFlashDmaRead(DMA_DEST_CHIPREG, DMA_BUFF_REG_ADDR, address+(ii-LutOffset)*4, 4);
		SpiFlashDmaRead2XMem(bgra, address+(ii-LutOffset)*4, 4);

		//read LUT data & compare
		for(j=0; j < 4; j++) {
			WriteTW88Page(PAGE4_SOSD );
			value = 0xa0 + j;						//?BGRA
			if(ii & 0x100) value += 0x08; 			//high
#ifdef MODEL_TW8836
			if(winno==1 || winno==2) value += 0x04;	//Group B
#endif
			WriteTW88(REG410,value);		
			WriteTW88(REG411,(BYTE)ii);				//addr 0
		
			//read twice or three times.
			value=ReadTW88(REG412);
			rcount=1;
			while(1) {		
				B0=ReadTW88(REG412);
				rcount++;
				if(B0 == value)
					break;
				value = B0;
			} 
			if(rcount > 3) {
				Printf("\n %d:%bd rcount:%bd",ii,j, rcount);
			}

			//bgra = ReadTW88(REG4D0+j);			

			if(B0 != bgra[j]) {
				error++;
				if(error <= 10)
					Printf("\nfail %d+%bd R:%bx Wrote:%bx", ii,j, B0, bgra[j]);
			}
		}
	}
	if(error==0)
		Printf("\n==>Success");		
}

void ChipTest_SPIDMA(BYTE wait)
{
/*
	WriteTW88Page(4);						 
	SpiFlashDmaDestType(DMA_DEST_CHIPREG, 0);
	SpiFlashDmaBuffAddr(DMA_BUFF_REG_ADDR);
	SpiFlashDmaReadLen(0);	//clear high & middle bytes 
	SpiFlashCmd(SPICMD_RDID, 1);	
	SpiFlashDmaReadLenByte(3);
	SpiFlashDmaStart(SPIDMA_READ,0, __LINE__);
	vid  = ReadTW88(REG4D0);
	dat0 = ReadTW88(REG4D1);
	cid  = ReadTW88(REG4D2);
*/
	BYTE r4c1, i;
	volatile BYTE value;

	WriteTW88Page(4);
	r4c1 = ReadTW88(REG4C1);	//save
	Printf("\nREG4C1:%02bx ",r4c1);
	Printf("  REG4C5:%02bx ",ReadTW88(REG4C5));
	Printf("  REG4D8:%02bx ",ReadTW88(REG4D8));
	Printf("  REG4D9:%02bx ",ReadTW88(REG4D9));



	WriteTW88(REG4C1, 1);		//1:At vertical blank
	WriteTW88(REG4C3, (DMA_DEST_CHIPREG << 6) | 1);
	WriteTW88(REG4C5, 0x80);	
	WriteTW88(REG4C6, 0x04);	//0x04D0 chip register address
	WriteTW88(REG4C7, 0xD0);
	WriteTW88(REG4CA, 0x00);	//dma length 3
	WriteTW88(REG4C8, 0x00);
	WriteTW88(REG4C9, 0x03);
	WriteTW88(REG4CA, 0x9F);	//cmd read JEDEC id
	WriteTW88(REG4D0, 0x00);	//clear buffer
	WriteTW88(REG4D1, 0x00);
	WriteTW88(REG4C2, 0x00);
	if(wait) {
		WriteTW88(REG4C4, 1);
		for(i=0; i < wait; i++) ;
	}
	else {
		//NO WAIT
		WriteTW88(REG4C4, 1);
	}
	//=========================
	// check REG4C4
	//=========================
	value=ReadTW88(REG4C4);
	if(value & 0x01) {
		for(i=0; i < 127; i++) {
			delay1ms(1);
			value=ReadTW88(REG4C4);
			if((value & 0x01)==0)
				break;
		}
		Printf("\nREG4C4:%02bx wait:%bd",value, i);
	}
	else
		Printf("\nREG4C4:%02bx",value);

	Printf("\nRead ID: %02bx %02bx %02bx",ReadTW88(REG4D0),ReadTW88(REG4D1),ReadTW88(REG4D2));
	WriteTW88(REG4C1, r4c1);	//restore
}


//=============================================================================
//
//=============================================================================
void MonitorChipTest(void)
{

	if(!stricmp( argv[1], "?")) {
		MonitorChipTest_Info();
		return;
	}
	//-------<<reg>>-----------------------------
	else if(!stricmp( argv[1], "reg")) {
		ChipTest_Register_ReadWrite();
	}
	//-------<<gpio>>-----------------------------
	else if(!stricmp( argv[1], "gpio")) {
		ChipTest_GPIO();
	}
	//-------<<power suspend & resume>>-----------------------------
	else if(!stricmp( argv[1], "resume")) {
//		SystemPowerSave(1);
//		SystemPowerResume(1);
	}
	//-------<<SPIOSD LUT test>>-----------------------------
	else if(!stricmp( argv[1], "sosdlut")) {
		BYTE winno;
		WORD LutOffset,size;
		DWORD address;

		if(argc < 6) {
			Printf("\nUsage:CTest sosdlut winno LutOffset size address");
			return;
		}
		winno = a2h(argv[2]);
		LutOffset = a2h(argv[3]);
		size = a2h(argv[4]);
		address = a2h(argv[5]);

		ChipTest_SOsdLut(winno, LutOffset, size, address);
	}
	//-------<<img6 win# lut#>>-----------------------------
	else if(!stricmp( argv[1], "dma")) {
		BYTE wait;
		if(argc < 3)	wait=0;
		else			wait = a2h(argv[2]);
		ChipTest_SPIDMA(wait);
	}
	//-------<<img7 win# lut#>>-----------------------------
	else if(!stricmp( argv[1], "??")) {
	}
	//-------<<??>>-----------------------------
	else if(!stricmp( argv[1], "??")) {
	}
	else
		Printf("\nInvalid command...");	
}
//=======================
#if 0
//readable==================================
code BYTE RegMask_Page0[256] = {
	/*000:*/0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*010:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*030:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
	/*050:*/0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*090:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*0A0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00 };
code BYTE RegMask_Page1[256] = {
	/*000:*/0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*020:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*030:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
	/*0D0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
code BYTE RegMask_Page2[256] = {
	/*000:*/0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*010:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*020:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*030:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*050:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0xFF,0xFF,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00 };
code BYTE RegMask_Page3[256] = {
	/*000:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*010:*/0xFF,0xFF,0xFF,0x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0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
code BYTE RegMask_Page4[256] = {
	/*000:*/0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
	/*010:*/0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*020:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
	/*030:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*040:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*050:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*060:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*070:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*080:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
	/*090:*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*060:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*070:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*080:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*090:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0A0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0B0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0C0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0D0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0E0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	/*0F0:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
#endif